package com.ts.proj.controller;


import com.ts.base.controller.BaseController;
import com.ts.proj.entity.SystemButtonEntity;
import com.ts.proj.service.SystemButtonService;
import com.ts.util.JurisdictionUtil;
import com.ts.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class SystemButtonController extends BaseController {


    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private SystemButtonService systemButtonService;

//    //权限对应的按钮
//    @RequestMapping("/admin-button-assign/{rights}/{btnRights}/{id}")
//    public ModelAndView adminButtonAssign(@PathVariable("rights") String rights, @PathVariable("btnRights") String btnRights, @PathVariable("id") Integer id){
//        ModelAndView modelAndView = this.getModelAndView();
//        modelAndView.addObject("rights",rights);
//        modelAndView.addObject("btnRights",btnRights);
//        modelAndView.addObject("role_id",id);
//        modelAndView.setViewName("admin/admin-button-assign");
//        return modelAndView;
//    }

    @RequestMapping("/admin-button-add/{id}")
    public ModelAndView buttonAddManage(@PathVariable("id") String id) {
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){
            SystemButtonEntity systemButtonEntity = systemButtonService.findById(Integer.valueOf(id));
            PageData pd = this.getPageData();
            if(null!=pd.get("menuId")&&!"".equals(pd.getString("menuId"))){
                modelAndView.addObject("menuId", pd.get("menuId").toString());
            }
            modelAndView.addObject("button", systemButtonEntity);
            viewName = "admin/admin-button-add";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }

}
